package com.controller;


import com.dao.UserDao1;
import com.po.User;
import com.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

@Autowired
private User user;
@Autowired
private UserService userService;


	//测试这个适合用做简单的操作
//	@RequestMapping("/login")
//	public String login(@RequestParam String name,@RequestParam String password) {
//user=userService.selectUserByname(name, password);
//		System.out.println(user.toString());
//		MyUser	user=userService.selectUserByname(name,password);
//		System.out.println(user);
//		System.out.println(name);

//		if (user.getName().equals(name)&&user.getPassword().equals(password))
//		{
//			System.out.println("登陆成功");
//			return "loginsuccess";
//		}else{
//			System.out.println("登陆失败");
//			return "loginfailure";
//		}

//	}

	/**
	 *
	 * @param request 请求数据
	 * @param model 为了返回数据
	 * @return   特定页面
	 */
	@RequestMapping("/login")
	public String login(HttpServletRequest request, Model model) {
		String name=request.getParameter("name");
		String password=request.getParameter("password");
		user=userService.selectUserByname(name,password);
		System.out.println(name);
		System.out.println(password);
//		System.out.println(user.toString());
//		user.getName().equals(name)&&user.getPassword().equals(password)
//		name.equals(user.getName())&&password.equals(user.getPassword())
//		if (name.equals(user.getName())&&password.equals(user.getPassword()))
//		{
//			System.out.println("登陆成功");
//			return "loginsuccess";
//		}else{
//			System.out.println("登陆失败");
//			return "loginfailure";
//		}
//		System.out.println(user);
		if(user!=null){
			System.out.println("登陆成功");
			model.addAttribute("name",name);
			return "loginsuccess";
		}else{
			System.out.println("登陆失败");
			model.addAttribute("name",name);
			return "loginfailure";
		}

	}

}
